{{- if include "is_basic_auth_enabled_in_any_crowd" . }}
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: crowd-basic-auth-proxy
  namespace: d8-{{ .Chart.Name }}
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: "/$2"
    nginx.ingress.kubernetes.io/proxy-body-size: 10m
  {{- if .Values.userAuthn.publishAPI.whitelistSourceRanges }}
    nginx.ingress.kubernetes.io/whitelist-source-range: {{ .Values.userAuthn.publishAPI.whitelistSourceRanges | join "," }}
  {{- end }}
  {{- include "helm_lib_module_labels" (list . (dict "app" "crowd-basic-auth-proxy")) | nindent 2 }}
spec:
  ingressClassName: {{ .Values.userAuthn.publishAPI.ingressClass | default (include "helm_lib_module_ingress_class" . | quote ) }}
  {{- if (include "helm_lib_module_https_ingress_tls_enabled" .) }}
  tls:
  - hosts:
    - {{ include "helm_lib_module_public_domain" (list . "api") }}
    secretName: {{ include "publish_api_certificate_name" . }}
  {{- end }}
  rules:
  - host: {{ include "helm_lib_module_public_domain" (list . "api") }}
    http:
      paths:
      - path: /basic-auth(\/?)(.*)
        pathType: ImplementationSpecific
        backend:
          service:
            name: crowd-basic-auth-proxy
            port:
              number: 7332
{{- end }}
